package copyengine.resource
{
    import com.catalystapps.gaf.data.GAFBundle;

    import copyengine.log.CELog;
    import copyengine.resource.resInfo.CEResInfoManger;
    import copyengine.resource.resInfo.MetaEachResFileInfo;
    import copyengine.resource.resProxy.CEResFIleDesc;
    import copyengine.resource.resProxy.CEResProxy;
    import copyengine.resource.resProxy.loadQueue.CEResLoadQueue;

    import flash.system.ApplicationDomain;

    import starling.textures.Texture;
    import starling.textures.TextureAtlas;

    public class CEResUtils
    {
        public function CEResUtils() {
        }


        public static function getGAFBundle(_fileName:String, _resProxy:CEResProxy):GAFBundle {return _resProxy.getRes(_fileName);}

        public static function getSpriteOrMovieClip(_symbolName:String, _fileName:String, _resProxy:CEResProxy):* {
            var domain:ApplicationDomain = _resProxy.getRes(_fileName);
            var msClass:Class = domain.getDefinition(_symbolName) as Class;
            return new msClass();
        }

        public static function getTexture(_fileName:String, _resProxy:CEResProxy):Texture {return _resProxy.getRes(_fileName);}

        public static function getTextureAtlas(_fileName:String, _resProxy:CEResProxy):TextureAtlas {return _resProxy.getRes(_fileName);}

        public static function getTextureFromAtlas(_fileName:String, _symbolName:String, _resProxy:CEResProxy):Texture {return getTextureAtlas(_fileName, _resProxy).getTexture(_symbolName);}

        public static function getDecompressedObj(_fileName:String, _resProxy:CEResProxy):* {return _resProxy.getRes(_fileName);}

        public static function getJSONObj(_fileName:String, _resProxy:CEResProxy):Object {return _resProxy.getRes(_fileName);}

        public static function getXML(_fileName:String, _resProxy:CEResProxy):XML {return _resProxy.getRes(_fileName);}

        public static function getText(_fileName:String, _resProxy:CEResProxy):String {return _resProxy.getRes(_fileName);}


        /**
         * 将某个文件Push到加载队列中
         * 注意!: 该文件必须可以在描述文件中找到@See CEResInfoManger
         * @param _fileName
         * @param _loadType
         * @param _needLoadResVector
         */
        public static function pushFileToNeedLoadResVector(_fileName:String, _loadType:String, _resLoadQueue:CEResLoadQueue):void {
            var resInfoFileInfo:MetaEachResFileInfo = CEResInfoManger.instance.getFileInfoByFileName(_fileName);
            if (resInfoFileInfo != null) {
                var fileDesc:CEResFIleDesc = new CEResFIleDesc();
                fileDesc.fileName = resInfoFileInfo.name;
                fileDesc.filePath = resInfoFileInfo.path;
                fileDesc.fileSize = resInfoFileInfo.size;
                fileDesc.fileType = _loadType;
                //TODO::对特殊Type类型的文件用Switch再做更进一步的处理
                _resLoadQueue.pushNeedLoadRes(fileDesc);
            } else {
                CELog.err("CEResUtils-> pushFileToResVector Can't find desc file in CEResInfoManger with name: " + _fileName);
            }
        }
    }

}
